﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using ajayumi.Test.WebUI.Utils;
using System.Text.RegularExpressions;

namespace ajayumi.Test.WebUI
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            SetLanguage();
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }



        private void SetLanguage()
        {
            //string language = string.Empty;
            //HttpCookie langCookie = Request.Cookies[Constants.Language_Key];
            //if (langCookie != null)
            //{
            //    language = langCookie.Value;
            //}
            //else
            //{
            //    string supportLanguage = Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
            //    if (!string.IsNullOrEmpty(supportLanguage))
            //    {
            //        string cultureName = Regex.Match(supportLanguage, "[^,;]+", RegexOptions.Multiline | RegexOptions.Compiled).Value;

            //        if (cultureName.StartsWith("en", StringComparison.CurrentCultureIgnoreCase))
            //        {
            //            Utility.SetLanguageToCookie(Constants.EnglishCultureName);
            //        }
            //        else
            //        {
            //            Utility.SetLanguageToCookie(Constants.ChineseCultureName);
            //        }
            //    }
            //    else
            //    { language = System.Threading.Thread.CurrentThread.CurrentCulture.ToString(); }
            //}

            string language = Constants.ChineseCultureName;
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(language);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language);
        }
    }
}